package in.muton.edushare.components.tasks.invitations.api;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.url.EduShareURLPanel;
import in.muton.edushare.wicket.models.CayenneModel;

import org.apache.wicket.model.IModel;

import com.edushare.common.dao.EnrolmentsDAO;
import com.edushare.common.vo.Courses;
import com.edushare.common.vo.Enrolments;

public class CourseInvitation extends Invitation {
	private static final long serialVersionUID = 6126768655690763819L;

	public CourseInvitation(IModel<Enrolments> enrol) {
		enrolment = enrol;
	}

	@Override
	public void accept() {
		enrolment.getObject().setStatus(Enrolments.ENROLLED);
		new EnrolmentsDAO(EduShareSession.get().getSessionORMInterface())
				.configureNewEnrolemnt(enrolment.getObject());
		EduShareSession.get().getSessionORMInterface().commitAllChanges();
		postInvitationTasks();
	}

	@Override
	public void decline() {
		new EnrolmentsDAO(EduShareSession.get().getSessionORMInterface())
				.removeUser(enrolment.getObject().getCourseInstance(),
						enrolment.getObject().getUser());
	}

	@Override
	public EduShareURLPanel getDestURL() {
		return new EduShareURLPanel("link", new CayenneModel<Courses>(enrolment
				.getObject().getCourseInstance().getCourse()));
	}

	private IModel<Enrolments> enrolment;

	@Override
	public void postInvitationTasks() {

	}
}
